lobsterlayui.main(['index', 'layer', 'form', 'element', 'table', 'tree'], {
    data: {
        $layui: null,
        basicDt: null,
        selectNodeId: 0
    },
    pageload: function (right) {
        console.log(right);
        this.initevent();
        this.getdataclass();
    },
    initevent() {
        var self = this;
        //搜索
        layui.form.on("submit(LAY-user-front-search)", function (data) {
            self.reloadData();
        });
    },
    getdataclass: function () {
        var self = this;
        // 获取基础字典数据
        lobsterlayui.GETAPI('tsbasedict.getdataclass').then(retdata => {
            var BaseData = [];  //字典数据 
            if (retdata.length > 0) {
                $.each(retdata, function (i, base) {
                    var predata = {
                        "id": base.ClassId,
                        "title": base.Name,
                    };

                    BaseData.push(predata);
                });
            }
            //父节点数据
            var treedata = [{
                title: '标准字典'
                , id: 0
                , children: BaseData
                , spread: true, disabled: true
            }];

            self.viewToTree(treedata);
        })
    },
    //树显示
    viewToTree: function (treelist) {
        var self = this;
        layui.tree.render({
            elem: '#TreeLeft',
            isJump: true,
            onlyIconControl: true,
            autoRefresh: true,
            customOperate: true,
            data: treelist,
            //edit: ['add', 'update', 'del'],
            click: function (obj) {

                var data = obj.data;
                //self.data.checkinfo = data;
                //console.log(self.data.checkinfo);
                $("#TreeLeft .nodeover").removeClass("nodeover");
                $(obj.elem).find(".layui-tree-main").eq(0).addClass("nodeover");
                self.data.selectNodeId = data.id;   //ClassId 注入到树结构的id中
                //self.data.parentName = data.title;
                self.tableLoad();

            }
        });
        //self.chooseFirstNode();
    },
    //表格数据加载
    tableLoad: function () {
        var self = this;

        //表格绑定
        self.data.basicDt = layui.table.render({
            elem: '#LAY-Record',
            headers: lobsterlayui.GetHeaderData(),
            where: {
                classid: self.data.selectNodeId,
                keywords: $("#txtkeyword").val()
            },
            //height: 'full-80',
            cellMinWidth: 80,
            url: lobsterlayui.GetLowCodeUrl("tsbasedict.getdatacontext"),
            page: true,
            ////even: true,
            cols: [[
                { width: '35%', field: 'Name', title: '名称' },
                { width: '10%', field: 'Code', title: '编码' },
                { width: '10%', field: 'Pym', title: '拼音码' },
                { width: '10%', field: 'Wbm', title: '五笔码' },
                { width: '10%', field: 'SortOrder', title: '排序号' },
                { width: '10%', field: 'DelFlag', title: '状态', templet: "#tplDelFlag" }
            ]],
            rowEvent: function (obj) {
                obj.tr.css({ 'background': '#5bd2ff', 'color': 'white' }).siblings().removeAttr('style')
            },
            parseData: function (res) {
                return {
                    code: res.code,
                    msg: res.msg,
                    count: res.data.count,
                    data: res.data.list
                }
            }
        });
    },
    //刷新（重新加载）
    reloadData: function () {
        var self = this;
        self.data.basicDt.reload({
            where: {
                classid: self.data.selectNodeId,
                keywords: $("#txtkeyword").val()
            },
            page: {
                curr: 1
            },
            done: function (res) {

            }
        });
    },
})